Tool

constructor(name: String, description: String, inputSerializer: KSerializer<TInput>, outputSerializer: KSerializer<TOutput>, executor: ToolExecutionContext<TContext>.(TInput) -> Flow<TOutput>, needsApproval: suspend (input: TInput, options: ToolPredicateOptions<TContext>) -> Boolean? = null, toModelOutput: (TOutput, ToolPredicateOptions<TContext>) -> ToolResultOutput? = null, strict: Boolean = true, inputExamples: List<String> = emptyList(), onInputStart: suspend (streamingId: String) -> Unit? = null, onInputDelta: suspend (streamingId: String, delta: String) -> Unit? = null, onInputAvailable: suspend (toolCallId: String, input: TInput) -> Unit? = null, metadata: Map<String, JsonElement> = emptyMap(), providerExecuted: Boolean = false, providerOptions: Map<String, JsonElement> = emptyMap())

Type Parameters

TInput

Application-defined input type, must be @Serializable. The model produces JSON matching its schema; the agent deserializes via inputSerializer before calling executor.

TOutput

Application-defined output type, must be @Serializable. Serialized into the model's tool-result message via outputSerializer, or summarized via toModelOutput if the raw output would be too verbose for the model.

TContext

Caller-supplied typed context propagated through the whole loop (set via callOptionsSchema, accessed inside the executor as this.context).

The internal executor always returns a Flow (the v6 alignment per tool.ts:68-71's AsyncIterable<OUTPUT> shape). Single-value tools built via tool wrap their suspend (TInput) -> TOutput body in a one-emission flow; streaming tools built via streamingTool pass their Flow body straight through. The agent loop's tool dispatcher collects with one-step lookahead — non-final emissions become StreamEvent.ToolResult(preliminary = true), the last emission is the final result that lands in the model's message log.